package br.ufpb.sistcomp.util;

import java.util.ArrayList;
import android.content.Context;
import br.ufpb.sistcomp.entity.Discipline;
import br.ufpb.sistcomp.persistence.PointPersistence;

/**
 * Class responsible for everything related to accounts of mathematical
 * application.
 * 
 * @author Diego Sousa - www.diegosousa.com
 * @version 1.0 Copyright (C) 2012 SistComp Empresa Jr.
 */

public class Calculator {

	private Context context;
	private PointPersistence pointPersistence;
	private ArrayList<Double> listPoints;
	private ArrayList<Double> listCRE;

	public Calculator() {
		this.pointPersistence = PointPersistence.getInstance(context);
	}

	public double calculatorMediaDiscipline(Discipline discipline) {

		double result = 0;
		listPoints = pointPersistence.locatePoints(discipline);

		for (double point : listPoints) {
			result += point;
		}
		result = result / listPoints.size();
		return result;
	}

	public double calculatorCRE() {
		double result = 0;
		listCRE = pointPersistence.listAllPointsAllDisciplines();

		for (double point : listCRE) {
			result += point;
		}
		result = result / listCRE.size();
		return result;
	}
}
